package com.jinzhi.jzweb.controller.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzapi.domain.UserDO;
import com.jinzhi.jzapi.utils.JWTUtil;
import com.jinzhi.jzweb.domain.JazSysLabelDO;
import com.jinzhi.jzweb.service.WxValidationService;
import com.jinzhi.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author mengzhichao
 * @create 2023-04-26-14:31
 */
@RestController
@RequestMapping("/jzApi/ApiJazUser")
public class ApiJazUserController {


    @Autowired
    private UserService userService; //用户表

    @Autowired
    private WxValidationService wxValidationService; // 敏感词校验


    /**
     * 修改用户信息
     * @return
     */
    @PostMapping("/updateUser")
    private Result<?> updateUser(String headPortrait,String nickname,String orderPhone){
		UserDO getUser = JWTUtil.getUser();
		UserDO userDO = userService.selectById(getUser.getId());
        userDO.setHeadPortrait(headPortrait);
        // 校验敏感词
//        Map map = wxValidationService.msgValidation(nickname);
//        if(Integer.parseInt(map.get("errcode").toString())!=0){
//            return Result.fail("调用微信小程序效验接口失败");
//        }
//        map = (Map) map.get("result");
//        if(Integer.parseInt(map.get("label").toString())!=100){
//            //文字效验不通过
//            return Result.fail("用户名包含敏感词，请更换后重试");
//        }
        userDO.setNickname(nickname);
        userDO.setUsername(nickname); //同步userName
        userDO.setOrderPhone(orderPhone);
        userService.updateById(userDO);
        return Result.ok();
    }



    /**
     * 查询用户信息
     * @return
     */
    @GetMapping("/selUser")
    private Result<?> selUser(){
		UserDO getUser = JWTUtil.getUser();
		UserDO userDO = userService.selectById(getUser.getId());
        return Result.ok(userDO);
    }


}
